package com.aldobucchi.utils
{
	import com.aldobucchi.core.comparison.ordered.IOrderedComparable;
	import com.aldobucchi.core.comparison.result.ComparisonResult;
	import com.aldobucchi.core.comparison.result.ComparisonResults;
	
	
	/**
	 * 
	 * A sample value object class used to work on typed objects during dev and testing.
	 * 
	 * @author aldo.bucchi@gmail.com
	 * @see com.aldobucchi.utils.SampleData
	 * 
	 */	
	public class PersonVO implements IOrderedComparable
	{
		
		
		public static var names:Array = String("Daddy,Aldo,Bob,John,Mary,Terry,Kate").split(",");


		[Bindable]		
		/**
		 * 
		 * A simple, bindable property
		 * 
		 * @return 
		 * 
		 */		
		public var name:String;
		
		
		
		private var _lastName:String;
		/**
		 * 
		 * A non-bindable read-only property
		 * 
		 * @return 
		 * 
		 */		
		public function get lastName():String
		{
			return _lastName;
		}
		
		
		/**
		 * 
		 * A simple, non-bindable property
		 * 
		 */		
		public var serial:int;
		
		
		
		/**
		 * 
		 * A read-only calculated property
		 * 
		 * @return 
		 * 
		 */		
		public function get fullName( ):String
		{
		
			return name + " " + _lastName;
		
		}		
		
		
		private static var personSerial:int = 0;
		
			
		public function PersonVO( name:String, lastName:String )	
		{
		
			this.name = name;
			
			_lastName = lastName;
			
			serial = personSerial++;

		}
		
		
		
		public function compare( other:* ):ComparisonResult
		{
			if ( this === other )	return ComparisonResults.EQUAL;
			
			var o:PersonVO = other as PersonVO;
			
			if ( o == null )		return ComparisonResults.DIFFERENT;
		
			if ( o.fullName == fullName ) 
				return ComparisonResults.EQUAL;
			
			return ( o.fullName > fullName ) ? ComparisonResults.BIGGER : ComparisonResults.SMALLER;			
		
		}
		
		
		
		public function clone( ):PersonVO
		{

			return new PersonVO( name, lastName );

		}
		
		
		
		
		
		
		
		
		
		

		/**
		 * 
		 * @param lastName
		 * @return 
		 * 
		 */
		public static function createFamily( lastName:String ):Array
		{
		
			var family:Array = [];
			for each ( var name:String in PersonVO.names )
			{
				family.push( new PersonVO( name, lastName ) );			
			}
		
			return family;
			
		}		
		
		
		
		
		
		
		
	}
	

}